package fr.idak.spring.tiles.hibernate.entity;

// Generated 1 janv. 2014 17:40:41 by Hibernate Tools 4.0.0

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * Users generated by hbm2java
 */
@Entity
@Table(name = "users")
public class User implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int userId;
	private String login;
	private Boolean enabled;
	private Set<Role> roles = new HashSet<Role>(0);

	public User() {
	}


	public User(int userId, String login, Boolean enabled) {
		this.userId = userId;
		this.login = login;
		this.enabled = enabled;
	}
	
	public User(String login, Boolean enabled) {
		this(0,login,enabled);
	}


	public User(int userId) {
		this(userId,null,false);
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO, generator="user_id_generator")
	@SequenceGenerator(name="user_id_generator", sequenceName="user_id_seq")
	@Column(name = "user_id", unique = true, nullable = false)
	public int getUserId() {
		return this.userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	@Column(name = "login", length = 50)
	public String getLogin() {
		return this.login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	@Column(name = "enabled")
	public Boolean getEnabled() {
		return this.enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	@ManyToMany(fetch=FetchType.LAZY)
    @JoinTable(name = "user_role", 
       joinColumns = { @JoinColumn(name = "user_id") }, 
       inverseJoinColumns = { @JoinColumn(name = "role_id") })
	public Set<Role> getRoles() {
		return roles;
	}


	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}
